package com.aweqy.porcelain.controller;

import com.aweqy.porcelain.common.BaseResponse;
import com.aweqy.porcelain.common.ResultUtils;
import com.aweqy.porcelain.entity.Dynasty;
import com.aweqy.porcelain.service.DynastyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 朝代信息控制器
 */
@Api(tags = "朝代信息管理")
@RestController
@RequestMapping("/dynasty")
@CrossOrigin(origins = "*")
public class DynastyController {
    
    @Autowired
    private DynastyService dynastyService;
    
    @ApiOperation("获取所有朝代信息（按时间排序）")
    @GetMapping("/list")
    public BaseResponse<List<Dynasty>> getAllDynasties() {
        List<Dynasty> dynasties = dynastyService.getAllDynastiesOrdered();
        return ResultUtils.success(dynasties);
    }
    
    @ApiOperation("根据朝代ID获取朝代详情")
    @GetMapping("/{dynastyId}")
    public BaseResponse<?> getDynastyById(
            @ApiParam("朝代ID") @PathVariable Integer dynastyId) {
        Dynasty dynasty = dynastyService.getDynastyById(dynastyId);
        if (dynasty == null) {
            return ResultUtils.error(404, "朝代不存在");
        }
        return ResultUtils.success(dynasty);
    }
} 